<template>
	<view>
		<u-swiper :height="250" :list="lun" :effect3d="true" :interval="3000" @click="click(idd)"></u-swiper>
		<uni-group title="新闻">
			<uni-card :title="item.title" v-for="(item,index) in xin" :thumbnail="base+item.imgUrl"
				@click="click(item.id)">
				<view class="" v-html="filler(item.summary)">
				</view>
				<view class="">
					评论数：{{item.commentNum}}
				</view>
				<view class="">
					发布时间：{{item.createTime}}
				</view>
			</uni-card>
		</uni-group>
		<uni-group style="position: fixed;bottom: 0%;right: 0%;left: 0%;z-index: 99;">
			<view class="item-container">
				<view class="thumb-box" v-for="(item1, index1) in list" :key="index1" @click="dian(item1.link)">
					<image class="item-menu-image" :src="item1.image" mode=""></image>
					<view class="item-menu-name">{{item1.text}}</view>
				</view>
			</view>
		</uni-group>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: [{
						image: '../../../../static/uview/example/js_select_bak.png',
						text: '首页',
						link:'index'
					},
					{
						image: '../../../../static/uview/example/js_select_bak.png',
						text: '志愿活动',
						link:'zhi'
					},
					{
						image: '../../../../static/uview/example/js_select_bak.png',
						text: '我的活动',
						link:'my'
					},
				],
				lun: [],
				base: '',
				xin: []
			}
		},
		onLoad() {
			this.base =uni.getStorageSync('serIP')
			this.getlun()
			this.getlun2()
		},
		onBackPress() {
			uni.switchTab({
				url:'../../index'
			})
		},
		methods: {
			dian(url){
				uni.navigateTo({
					url:url
				})
			},
			filler(str) {
				return str.length > 16 ? str.substring(0, 14) + '...' : str
			},
			getlun2() {
				this.$get(this.base + '/prod-api/api/volunteer-service/news/list').then((res) => {
					this.xin = this.arr(res.rows)
					console.log(res.rows)
				})
			},
			getlun() {
				this.$get(this.base + '/prod-api/api/volunteer-service/ad-banner/list').then((res) => {
					res.data.forEach((item) => {
						this.lun.push({
							image: this.base + item.imgUrl,
							id: item.targetId
						})
					})
				})
			},
			arr(arr) {
				for (var i = 0; i < arr.length - 1; i++) {
					for (var j = 0; j < arr.length - 1; j++) {
						if (new Date(arr[j].createTime) < new Date(arr[j + 1].createTime)) {
							var str = arr[j]
							arr[j] = arr[j + 1]
							arr[j + 1] = str
						}
					}
				}
				return arr
			}
		}
	}
</script>

<style>
	.item-container {
				display: flex;
				flex-wrap: wrap;
			}
		
			.thumb-box {
				width: 33.33%;
				display: flex;
				align-items: center;
				justify-content: center;
				flex-direction: column;
				margin-top: 20rpx;
			}
		
			.item-menu-image {
				width: 80rpx;
				height: 80rpx;
			}
</style>
